<?php

class HeaderBox extends AbstractBox {
	protected $template = 'main/header.tpl';
	
	protected function setup() {
		$pageRepository = new PageRepository();
		$pageRepository->addOrderBy(array('sorting' => 'ASC'));
		$mainPages = $pageRepository->getByPid(Page::MAIN_MENU_PID);
		
		$mainPagesUidList = array();
		$menu = array();
		foreach ($mainPages as $page) {
			$mainPagesUidList[] = $page['uid'];
			$menu[$page['uid']]['page'] = $page;
		}
		
		if ($mainPagesUidList) {
			$subPages = $pageRepository->getByPid($mainPagesUidList);
			
			if ($subPages) {
				foreach ($subPages as $subPage) {
					$submenu = array();
					$submenu['page'] = $subPage;
					$submenu['subpages'] = $pageRepository->getByPid($subPage['uid']);
					
					$menu[$subPage['pid']]['submenu'][$subPage['uid']] = $submenu;
				}
			}
		}
		
		MySmarty::assign('menu', $menu);
		
		MySmarty::assign('actualMainMenuItem', isset($GLOBALS['TSFE']->rootLine[1]) ? $GLOBALS['TSFE']->rootLine[1] : NULL);
		MySmarty::assign('actualSecondaryMenuItem', isset($GLOBALS['TSFE']->rootLine[2]) ? $GLOBALS['TSFE']->rootLine[2] : NULL);
		MySmarty::assign('actualThirdMenuItem', isset($GLOBALS['TSFE']->rootLine[3]) ? $GLOBALS['TSFE']->rootLine[3] : NULL);
		
		MySmarty::assign('baseUrl', $GLOBALS['TSFE']->config['config']['baseURL']);
	}
}

?>